package com.toubutu.audio.controller;

import com.toubutu.anno.LoginRequired;
import com.toubutu.audio.dto.QueryHistoryDto;
import com.toubutu.audio.dto.RecordHistoryDto;
import com.toubutu.audio.service.HistoryService;
import com.toubutu.audio.vo.HistoryVo;
import com.toubutu.common.PageUtils;
import com.toubutu.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 戒躁
 * @since 2024-02-25
 */
@RestController
@RequestMapping("/history")
@Api(tags = "用户观影历史记录接口")
@LoginRequired
public class HistoryController {

    @Resource
    private HistoryService historyService;

    @PostMapping("/list")
    @ApiOperation("分页获取用户历史记录")
    public Result<PageUtils<HistoryVo>> getUserHistoryList(@RequestBody QueryHistoryDto dto){
        return Result.ok(historyService.getUserHistory(dto));
    }

    @PostMapping("/record")
    @ApiOperation("记录用户观看历史记录")
    public Result<Void> record(@RequestBody RecordHistoryDto dto){
        historyService.recordHistory(dto);
        return Result.ok();
    }
}
